package cn.myeasyai.service;

import cn.myeasyai.dto.UserDTO;
import com.alibaba.fastjson.JSON;
import org.dromara.easyai.function.Sigmoid;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.springframework.boot.test.context.SpringBootTest;

import javax.annotation.Resource;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.InputStream;
import java.util.List;


@SpringBootTest
class FaceServiceTest {

    @Resource
    FaceService faceService;

    @BeforeEach
    void setUp() {
    }

    @AfterEach
    void tearDown() {
    }

    @Test
    void faceInit() {

        File root = new File("/Users/yangjie/Downloads/imageTest");
        final File[] files = root.listFiles();
        for (File file :files){
            try {
                InputStream inputStream = new FileInputStream(file);
                UserDTO userDTO = new UserDTO();
                userDTO.setUserName(file.getName());
                final UserDTO userDTO1 = faceService.faceInit(inputStream, userDTO);
                System.out.println(userDTO1);
            } catch (Exception e) {
                System.out.println(e.getMessage());
            }
        }



    }

    @Test
    void faceInitOnce() {
        File file = new File("/Users/yangjie/Downloads/imageTest/36541733302986_.pic.jpg");
        try {
            InputStream inputStream = new FileInputStream(file);
            UserDTO userDTO = new UserDTO();
            userDTO.setUserName(file.getName());
            final UserDTO userDTO1 = faceService.faceInit(inputStream, userDTO);
            System.out.println(userDTO1);
        } catch (Exception e) {
            System.out.println(e.getMessage());
        }


    }
    @Test
    void faceSearch() {
//        String pic = "IMG_6263.png," +
//                "IMG_6262.png," +
//                "IMG_6261.png," +
//                "IMG_6260.png," +
//                "IMG_6259.png," +
//                "IMG_6258.png";
        String pic = "36631733303056_.pic.jpg";

        final String[] split = pic.split(",");
        for (String s : split){
            File file = new File("/Users/yangjie/Downloads/imageTest/"+s);
            try {
                InputStream inputStream = new FileInputStream(file);
                final List<UserDTO> userDTOS = faceService.faceSearch(inputStream);
                System.out.println(JSON.toJSONString(userDTOS));
            } catch (FileNotFoundException e) {
                e.printStackTrace();
            }

        }



    }
}